//
//  RHLocalFaultAlarmListCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2024/4/9.
//

#import "RHLocalFaultAlarmListCell.h"
@interface RHLocalFaultAlarmListCell()
@property(nonatomic,strong)QMUILabel *alarmCodeValueLab;

@property(nonatomic,strong)QMUILabel *alarmDesContentLab;

@property(nonatomic,strong)QMUILabel *reportDateLab;

@end
@implementation RHLocalFaultAlarmListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}
-(void)setAlarmModel:(RHDeviceAlarmModel *)alarmModel
{
    _alarmModel = alarmModel;
    self.alarmCodeValueLab.text   = _alarmModel.faultCode;
   
    NSTimeInterval timestamp = _alarmModel.reportedTime/1000;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    self.reportDateLab.text = [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:timestamp]];
    
    
    self.alarmDesContentLab.text  = ValidNullDataToString(_alarmModel.faultDetail, @" ");

    [self.alarmDesContentLab sizeToFit];
    NSInteger row = self.alarmDesContentLab.size.height/self.alarmDesContentLab.font.lineHeight;
    if(row ==1){
        self.alarmDesContentLab.textAlignment = NSTextAlignmentRight;
    }else{
        self.alarmDesContentLab.textAlignment = NSTextAlignmentLeft;
    }
    
    
}
-(void)setupUI{
    self.contentView.backgroundColor = kRGB(246, 248, 250);
    UIView *bgView = [[UIView alloc]init];
    [self.contentView addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 8;
    //编号
    
    self.alarmCodeValueLab = [[QMUILabel alloc]init];
    self.alarmCodeValueLab.font = [UIFont systemFontOfSize:14];
    self.alarmCodeValueLab.textColor = [UIColor colorWithHexString:@"3F4443"];
    self.alarmCodeValueLab.textAlignment = NSTextAlignmentLeft;
    self.alarmCodeValueLab.text = @"W1,W2";
    [bgView addSubview:self.alarmCodeValueLab];
    
    //上报时间
    self.reportDateLab = [[QMUILabel alloc]init];
    self.reportDateLab.font = kSYSTEMFONT(12);
    self.reportDateLab.textColor = kColorRGBA(63, 68, 67, 0.5);
    self.reportDateLab.textAlignment = NSTextAlignmentRight;
    self.reportDateLab.text = @"2023-07-23 23:23:55";
    [bgView addSubview:self.reportDateLab];
    
    //line
    UIView *line = [[UIView alloc]init];
    line.backgroundColor = [UIColor colorWithHexString:@"EBEDF0"];
    [self.contentView addSubview:line];
    
    
    //描述
    QMUILabel *alarmDesTitleLab = [[QMUILabel alloc]init];
    alarmDesTitleLab.font = [UIFont systemFontOfSize:14];
    alarmDesTitleLab.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    alarmDesTitleLab.textAlignment = NSTextAlignmentLeft;
    alarmDesTitleLab.text = @"描述:".rh_localized;
    [bgView addSubview:alarmDesTitleLab];
    
    self.alarmDesContentLab = [[QMUILabel alloc]init];
    self.alarmDesContentLab.font = [UIFont systemFontOfSize:14];
    self.alarmDesContentLab.textColor = [UIColor colorWithHexString:@"3F4443"];
    self.alarmDesContentLab.lineBreakMode = NSLineBreakByCharWrapping;
    self.alarmDesContentLab.numberOfLines = 0;
    self.alarmDesContentLab.textAlignment = NSTextAlignmentRight;
    self.alarmDesContentLab.text = @"故障了================-------------=故障000000000009fdsfasjkfj茵茵喹中是国囿中有人";
    [bgView addSubview:self.alarmDesContentLab];
    
    
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 10, 5, 10));
    }];
    kWeakSelf;
   
    [self.alarmCodeValueLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(15);
        make.right.equalTo(self.reportDateLab.mas_left).offset(-15);
    }];
    
    [self.reportDateLab sizeToFit];
    [self.reportDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.top.mas_offset(18);
        make.width.offset(weakSelf.reportDateLab.width+5);
    }];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.alarmCodeValueLab);
        make.top.equalTo(weakSelf.alarmCodeValueLab.mas_bottom).offset(15);
        make.right.equalTo(weakSelf.reportDateLab);
        make.height.offset(1);
    }];
    
    [alarmDesTitleLab sizeToFit];
    [alarmDesTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(line);
        make.top.equalTo(line.mas_bottom).offset(10);
        make.width.offset(alarmDesTitleLab.width+1);
    }];
    [self.alarmDesContentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(alarmDesTitleLab.mas_right).offset(5);
        make.top.equalTo(alarmDesTitleLab);
        make.right.equalTo(line);
        make.bottom.mas_offset(-45);
    }];
    
    
    
    
    
    
}
@end
